﻿Module ModEventDeposit

    Sub Main()

        Dim sFuncName As String = String.Empty
        Dim sErrDesc As String = String.Empty
        Dim oEventSales As AE_EASIPOS_INTEGRATION_DLL.clsEventSales = New AE_EASIPOS_INTEGRATION_DLL.clsEventSales

        Dim oDataSetSO As DataSet = Nothing
        Dim oDSEventDeposit As DataSet = Nothing
        Try

            sFuncName = "Main()"
            Console.WriteLine("Starting Function", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting function", sFuncName)

            'Getting the Parameter Values from App Cofig File
            Console.WriteLine("Calling GetSystemIntializeInfo() ", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
            If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)


            P_sConString = String.Empty
            P_sConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sIntDBName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword
            AE_EASIPOS_INTEGRATION_DLL.P_sConString = P_sConString

            'Getting the Data from Invoice Table as DataSet
            Console.WriteLine("Calling EventOrder_DataSet() ", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling EventOrder_DataSet()", sFuncName)

            oDataSetSO = oEventSales.EventOrder_DataSet(P_sConString)

            Console.WriteLine("Calling EventDeposit_DataSet() ", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling EventDeposit_DataSet()", sFuncName)

            oDSEventDeposit = oEventSales.EventDeposit_DataSet(P_sConString)


            If Not oDataSetSO Is Nothing Or Not oDSEventDeposit Is Nothing Then

                'Function to connect the Company
                If p_oCompany Is Nothing Then
                    Console.WriteLine("Calling ConnectToTargetCompany() ", sFuncName)
                    If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ConnectToTargetCompany()", sFuncName)
                    If ConnectToTargetCompany(p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)
                End If


                'Function To Update the Sales Order linelevel and Payment
                If Not oDataSetSO Is Nothing Then
                    Console.WriteLine("Calling UpdateEvent() ", sFuncName)
                    If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling UpdateEvent()", sFuncName)
                    If oEventSales.UpdateEvent(oDataSetSO, p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)
                End If

                'Function to Create Incoming payment for Event Order

                If Not oDSEventDeposit Is Nothing Then
                    Console.WriteLine("Calling EventDeposit() ", sFuncName)
                    If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling EventDeposit()", sFuncName)
                    If oEventSales.EventDeposit(oDSEventDeposit, p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)
                End If

            End If
            Console.WriteLine("Completed with SUCCESS ", sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)

        Catch ex As Exception
            sErrDesc = ex.Message
            Call WriteToLogFile(sErrDesc, sFuncName)
            Console.WriteLine("Completed with ERROR : " & sErrDesc, sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
        End Try

    End Sub

End Module
